﻿var socket = null;
var qqFrame = null;
var loginFrame = null;

function TopLoad() {
    socket = new Socket('192.168.3.190', 5354, pro_cmd);
    var frames = window.frames;
    for (var i = 0; i < frames.length; i++) {
        var name = frames[1].name;
        switch (name) {
            case 'qqFrame': qqFrame = window.frames[i]; break;
            case 'loginFrame': loginFrame = window.frames[i]; break;
            default:
        }
    }
}

function send_cmd(tid, content) {
    switch (tid) {
        case 101:
            {
                LoadExt.loading();
                break;
            }
        default:
    }
    socket.Send(tid, content);
}

function pro_cmd(data) {
    var tid = data.tid;
    var content = data.content;
    switch (tid) {
        case 103:
            {
                $('#div_loginFrame').hide();
                qqFrame.QQ.loadUserList(content);
                LoadExt.unloading();
                $('#div_qqFrame').show();
                break;
            }
        default:
    }
}

Login = {
    LoginTo: function () {
        var userPassword = [$('#txtUser').val(), $('#txtPassword').val()];
        top.send_cmd(101, userPassword.join('#'));
    }
};

QQ = {
    loadUserList: function (data) {
        var userList = data.split('#');
        $('#EQQ_Class_online_OnlineCounter').html(userList.length);
        var html = '';
        for (var i = 0; i < userList.length; i++) {
            var item = userList[i].split('|');
            html += '<div class="EQQ_BuddyList_Buddy" style="background-color: transparent;">                                                   ';
            html += '                                                    <div class="EQQ_BuddyList_ClientType">                                 ';
            html += '                                                    </div>                                                                 ';
            html += '                                                    <div class="EQQ_BuddyList_AvatarContainer">                            ';
            html += '                                                        <img class="EQQ_BuddyList_Avatar" src="./qq_files/getface(1).png"> ';
            html += '                                                        <div class="EQQ_BuddyList_State">                                  ';
            html += '                                                        </div>                                                             ';
            html += '                                                    </div>                                                                 ';
            html += '                                                    <div class="EQQ_BuddyList_RightContainer">                             ';
            html += '                                                        <div class="EQQ_BuddyList_Nick ">                                  ';
            html += '                                                            ' + item[1] + '</div>                                          ';
            html += '                                                        <div title="" class="EQQ_BuddyList_Sign">                          ';
            html += '                                                        </div>                                                             ';
            html += '                                                    </div>                                                                 ';
            html += '                                                </div>                                                                     ';
        }
        $('#EQQ_Class_online_online').html(html);
    }
}